<?php
    if (!isset($addTag)) {
        $addTag = true;
    }
    if ($addTag == true) {
        require_once("../core/functions.php");
        Core::getResource("Controller.LoginController");
        session_start();
        if (!isset($_GET["person"])) {
            Core::redirect("404.php");
        }
        ?>
        <!DOCTYPE html>
        <html>
            <body>
                <style>
                    html, body {
                        margin: 0;
                        padding: 0;
                    }
                </style>
                <?php
            }

            $id = $_GET["person"];
            $person = Person::getPerson($id);
            if ($addTag == false) {
                $applied = Person::getAppliedByPerson($id);
            }
        ?>
        <style>
            table tr > :first-child {
                width: 15em;
            }
            table tr:first-child td {
                background-color: #0099CC;
                color: white;
                padding: 10px;
            }
            tr:nth-child(even) {
                background-color: #C8F4FF;
            }
            tr:nth-child(odd) {
                background-color: #FFFFFF;
            }
            table td {
                border: 1px solid #00749B;
                padding: 5px;
            }
            table {
                border-collapse: collapse;
                width: 100%;
            }
        </style>
        <table id="profileTable">
            <tr><td colspan="2"><h1><?= ($person ? $person["firstName"] . ' ' . $person["lastName"] : "hi") ?></h1></td></tr>
            <tr><td><b>Account Type : </b></td><td><?= $person["accountType"] ?></td></tr>
            <tr><td><b>Gender : </b></td><td>
                    <?php
                        if ($person["gender"] == "M") {
                            echo "Male";
                        } else if ($person["gender"] == "F") {
                            echo "Female";
                        } else {
                            echo "Other";
                        }
                    ?>
                </td></tr>
            <tr><td><b>Email : </b></td><td><?= $person["email"] ?></td></tr>
            <tr><td><b>Contact Number : </b></td><td><?= $person["contactNumber"] ?></td></tr>
            <tr><td><b>Skills : </b></td><td><?= $person["skills"] ?></td></tr>
            <tr><td><b>Availability : </b></td><td><?= $person["availability"] ?></td></tr>
            <tr><td><b>Drivers Licence : </b></td><td><?= ($person["driversLicence"] ? "Yes" : "No") ?></td></tr>
            <tr><td><b>Paperwork Status : </b></td><td><?= $person["paperworkStatus"] ?></td></tr>
            <tr><td><b>Offer : </b></td><td><?= ($person["offer"] ? "Yes" : "No") ?></td></tr>
            <tr><td><b>University Id : </b></td><td><?= $person["universityId"] ?></td></tr>
            <tr><td><b>Degree Name : </b></td><td><?= $person["degreeName"] ?></td></tr>
            <tr><td><b>Major(s) : </b></td><td><?= $person["majors"] ?></td></tr>
            <tr><td><b>Year of Degree : </b></td><td><?= $person["yearOfDegree"] ?></td></tr>
            <tr><td><b>High School : </b></td><td><?= $person["highSchool"] ?></td></tr>
            <tr><td><b>Entry to UTS : </b></td><td><?= $person["entryToUTS"] ?></td></tr>
            <tr><td><b>Scholarships : </b></td><td><?= $person["scholarships"] ?></td></tr>
            <tr><td><b>Workshops : </b></td><td><?= $person["workshops"] ?></td></tr>
            <tr><td><b>Extra Curricular Activities : </b></td><td><?= $person["extraCurricularActivities"] ?></td></tr>
            <tr><td><b>Refugee : </b></td><td><?= ($person["refugee"] ? 'Yes' : 'No') ?></td></tr>
            <tr><td><b>Indigenous : </b></td><td><?= ($person["indigenous"] ? 'Yes' : 'No') ?></td></tr>
            <tr><td><b>Contract Expiration : </b></td><td><?= $person["contractExpiration"] ?></td></tr>
            <tr><td><b>Account Activated : </b></td><td><?= ($person["activated"] ? "Yes" : "No") ?></td></tr>
            <?php if ($addTag == false) { ?>
                    <tr><td colspan="2" style="background-color: #0099CC;color: white;"><h2>Last Five Events : </h2></tr>

        <?php
        for ($i = 0; $i < count($applied); $i++) {
            $data = $applied[$i];
            ?>
                        <tr><td><h2>Role Title : </h2></td><td><b>
                                    <a title="View Role" href="viewrole.php?roleId=<?= $data["role"] ?>"><?= $data["title"] ?></a></b>
                            </td></tr>
                        <tr><td><b>Attended : </b></td><td><?= ($data["attended"] ? "Yes" : "No") ?></td></tr>
                        <tr><td><b>Hours Worked : </b></td><td><?= $data["hoursWorked"] ?></td></tr>              
            <?php
        }
    }
?>
        </table>
            <?php
                if ($addTag == true) {
                    ?>
            </body>
        </html>
        <?php
    }
?>